<template>
  <view class="template-product tn-safe-area-inset-bottom">
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'>
        <text @click="goBack" class='icon tn-icon-left'></text>
        <text @click="goHome" class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar>
    
	<view v-if="article">
		
		<image @click="TanPreviewImage([article.avatar], 0)" class="card-swiper" :src="article.avatar" mode="aspectFill"></image>
		<!-- 作者信息 -->
		
<!-- 		  <view class="tn-margin-sm tn-bg-white">
		  	<view class="tn-flex tn-flex-row-between tn-flex-col-center">
		  		<view class="justify__author__info">
		  			<view class="tn-flex tn-flex-row-center">
		  				<view class="tn-flex tn-flex-row-center tn-flex-col-center">
		  					<view class="">
		  						<tn-avatar class="" shape="circle" :src="article.user_id[0].avatar_file.url" size="lg">
		  						</tn-avatar>
		  					</view>
		  					<view class="tn-padding-right tn-text-ellipsis">
		  						<view class="tn-padding-right tn-color-black tn-padding-left-sm tn-text-bold tn-text-lg">
		  							{{ article.user_id[0].nickname }}</view>
		  						<view
		  							class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray">
		  							{{ article.create_time }}</view>
		  					</view>
		  				</view>
		  			</view>
		  		</view>
		  	</view>
		  </view> -->
		
		
		
		<view class="tn-margin">
		  <view class="tn-flex tn-flex-row-between">
		    <view class="justify-content-item tn-text-bold tn-text-xl">
		      {{article.title}}
		    </view>
		  </view>
		</view>
		
		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>
		
		
		<view class="tn-margin">
		  <view class="tn-flex tn-flex-row-between">
		    <view class="justify-content-item tn-text-bold tn-text-xl">
		      摘要
		    </view>
		  </view>
		</view>
		
		<view class="content-backgroup tn-margin">
		 {{article.excerpt}}
		</view>
		
		
		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>
		
		<view class="tn-margin">
		  <view class="tn-flex tn-flex-row-between">
		    <view class="justify-content-item tn-text-bold tn-text-xl">
		      正文
		    </view>
		  </view>
		</view>
		
		<view class="content-backgroup tn-margin">
			<mp-html :content="article.content" />
		</view>
		
		
		<view class="tn-padding-xl tn-margin"></view>
	</view>

	
    <!-- 引用组件 -->
    <tn-skeleton :show="showSkeleton"></tn-skeleton>
    <!-- 回到首页悬浮按钮-->
    <nav-index-button></nav-index-button>
    
  </view>
</template>

<script>
	import NavIndexButton from '@/libs/components/nav-index-button.vue'
	import day from 'tuniao-ui/day.js'
	const db = uniCloud.database()
	const bannerCollection = db.collection('opendb-banner')
	const userCollection   = db.collection('uni-id-users')
	const articleCollection = db.collection('opendb-news-articles')
	const dbCmd = db.command
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			NavIndexButton
		},
		data() {
			return {
				day: day, //时间戳处理
				article: null,
				author:null,
				showSkeleton: true,
				
			}
		},
		onLoad(info) {
			this.uid = info.uid
			this.getArticle(info.uid)
			this.contentHideShowHeight = uni.upx2px(56) * 3
		},
		computed: {},
		methods: {
			goBack() {
				uni.navigateBack({})
			},
			goHome(){
				uni.switchTab({
					url:'/pages/share/share'
				})
			},
			async getArticle(uid){
				const article = articleCollection.field('user_id, _id, avatar, title, publish_data, excerpt, content, create_time').getTemp()
				const user	  = userCollection.field('_id, nickname, username, avatar_file').getTemp()
				db.collection(article, user).where(`_id=="${uid}"`).get().then(res =>{
					let content = res.result.data
					this.article = content[0]
					this.showSkeleton = false
				}).catch(err =>{
					console.error(err)
				})
			},
			// 预览图片
			TanPreviewImage(ImageList, index) {
				let photoList = ImageList.map(item => {
					return item;
				});
				uni.previewImage({
					current: index,
					urls: photoList,
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
  @import '@/static/css/templatePage/custom_nav_bar.scss';
  /* 轮播视觉差 start */
  .card-swiper {
    height: 550rpx !important;
	width: 100%;
  }
  
  /* 间隔线 start*/
  .tn-strip-bottom {
   width: 100%;
   border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
  }
   /* 间隔线 end*/
  /* 标题 start */
  .nav_title {
    -webkit-background-clip: text;
    color: transparent;
    
    &--wrap {
      position: relative;
      display: flex;
      height: 120rpx;
      font-size: 46rpx;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
      background-size: cover;
    }
  }
  /* 标题 end */
  
  /* 底部tabbar start*/
  .footerfixed{
   position: fixed;
   width: 100%;
   bottom: 0;
   z-index: 999;
   background-color: #FFFFFF;
   box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  
  /* 标签内容 start*/
  .tn-tag-content {
    &__item {
      display: inline-block;
      line-height: 45rpx;
      padding: 10rpx 30rpx;
      margin: 20rpx 20rpx 5rpx 0rpx;
      
      &--prefix {
        padding-right: 10rpx;
      }  
    }
  }
  /* 标签内容 end*/
  
  /* 内容图 start */
  .content-backgroup {
    z-index: -1;
  
    .backgroud-image {
      border-radius: 15rpx;
      width: 100%;
    }
  }
  /* 内容图 end */
  
  /* 文章内容 start*/
  .tn-blogger-content {
    &__wrap {
      box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.12);
      border-radius: 20rpx;
      margin: 15rpx;
    }
    
    &__info {
      &__btn {
        margin-right: -12rpx;
        opacity: 0.5;
      }
    }
    
    &__label {
      &__item {
        line-height: 45rpx;
        padding: 0 20rpx;
        margin: 5rpx 18rpx 0 0;
        
        &--prefix {
          color: #E83A30;
          padding-right: 10rpx;
        }
      }
      
      &__desc {
        line-height: 35rpx;
      }
    }
    
    &__main-image {
      border-radius: 16rpx 16rpx 0 0;
      
      &--1 {
        max-width: 690rpx;
        min-width: 690rpx;
        max-height: 400rpx;
        min-height: 400rpx;
      }
      
      &--2 {
        max-width: 260rpx;
        max-height: 260rpx;
      }
      
      &--3 {
        height: 212rpx;
        width: 100%;
      }
    }
    
    &__count-icon {
      font-size: 30rpx;
      padding-right: 5rpx;
    }
  }
  
  .image-book{
    padding: 150rpx 0rpx;
    font-size: 16rpx;
    font-weight: 300;
    position: relative;
  }
  .image-picbook{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:top;
    border-radius: 20rpx 20rpx 0 0;
  }
  /* 文章内容 end*/
</style>
